修改C1DataGrid for Silverlight中CheckBox列的显示外观

文章主要描述了如何修改C1DataGrid for Silverlight中CheckBox列的显示外观

发布于 2012/11/16 00:00

ComponentOne Enterprise

在C1DataGrid for Silverlight中,如果包含DataGridCheckBoxColumn类型的列,你会发现该列中单元格处于非编辑状态时,CheckBox都被显示成灰色。



本文也将主要介绍如何改变CheckBox列处于非编辑状态时的显示样式,基本思路是在LoadedCellPresenter事件中将C1.Silverlight.DataGrid.ReadOnlyCheckBox替换为正常的CheckBox,代码如下:

 
void c1DataGrid1_LoadedCellPresenter(object sender, C1.Silverlight.DataGrid.DataGridCellEventArgs e)
    {
        if (e.Cell.Column.GetType() == typeof(C1.Silverlight.DataGrid.DataGridCheckBoxColumn))
        {                
            CheckBox newCheckBox = new CheckBox();
                
            System.Windows.Data.Binding bnd = new System.Windows.Data.Binding();
            bnd.Source = e.Cell;
            bnd.Path = new PropertyPath("Value");
            bnd.Mode = System.Windows.Data.BindingMode.TwoWay;
            newCheckBox.SetBinding(CheckBox.IsCheckedProperty, bnd);
            e.Cell.Presenter.Content = newCheckBox;
            e.Cell.Presenter.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
            e.Cell.Presenter.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
        }
    }
复制代码

运行截图:


源码下载:VS2010 + ComponentOne Studio for Silverlight 2012V2
C#:


VB.NET:

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态